@echo off
chcp 65001 >nul
echo ====================================
echo   修复 Prisma Client 生成问题
echo ====================================
echo.

echo [1] 清理旧的 Prisma Client...
if exist "api\node_modules\.prisma" (
    echo   删除 API 服务的旧 Prisma Client...
    rmdir /s /q "api\node_modules\.prisma"
)

if exist "admin\node_modules\.prisma" (
    echo   删除 Admin 服务的旧 Prisma Client...
    rmdir /s /q "admin\node_modules\.prisma"
)

echo.
echo [2] 生成 API 服务的 Prisma Client...
cd api
call npx prisma generate --schema=../shared/prisma/schema.prisma
if %errorlevel% neq 0 (
    echo [错误] API 服务 Prisma Client 生成失败
    cd ..
    pause
    exit /b 1
)
cd ..

echo.
echo [3] 生成 Admin 服务的 Prisma Client...
cd admin
call npx prisma generate --schema=../shared/prisma/schema.prisma
if %errorlevel% neq 0 (
    echo [错误] Admin 服务 Prisma Client 生成失败
    cd ..
    pause
    exit /b 1
)
cd ..

echo.
echo [4] 验证生成结果...
if exist "api\node_modules\.prisma\client" (
    echo   ✓ API 服务: Prisma Client 已生成
) else (
    echo   ✗ API 服务: Prisma Client 生成失败
)

if exist "admin\node_modules\.prisma\client" (
    echo   ✓ Admin 服务: Prisma Client 已生成
) else (
    echo   ✗ Admin 服务: Prisma Client 生成失败
)

echo.
echo ====================================
echo   修复完成！
echo ====================================
pause

